Component({
    properties: {
        clear: {
            type: Boolean,
            value: false
        }
    },

    data: {
        chooseImgs: []
    },

    methods: {
        handleChooseImg() {
            wx.chooseImage({
                count: 9,
                sizeType: ['original', 'compressed'],
                sourceType: ['album', 'camera'],
                success: (res) => {
                    // tempFilePath可以作为img标签的src属性显示图片
                    const tempFilePaths = res.tempFilePaths;
                    const chooseImgs = [...this.data.chooseImgs, ...tempFilePaths];
                    this.setData({chooseImgs});
                    this.triggerEvent('getImages', {images: chooseImgs});
                }
            })
        },

        handleDeleteImg(e) {
            const {index} = e.currentTarget.dataset;
            const {chooseImgs} = this.data;
            chooseImgs.splice(index, 1);
            this.setData({chooseImgs});
            this.triggerEvent('getImages', {images: chooseImgs});
        },

        handlePreview(e) {
            const {index} = e.currentTarget.dataset;
            const {chooseImgs} = this.data;
            wx.previewImage({
                current: chooseImgs[index],
                urls: chooseImgs
            })
        },
    }
})
